package com.indexingsystem.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.ProgramLogVo;
import com.indexingsystem.boss.Vo.ProgramLogsVo;
import com.indexingsystem.boss.admin.mapper.ProgramLogsMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.ProgramLogs;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.system.service.IProgramLogsService;

@Service
public class ProgramLogsServiceImpl implements IProgramLogsService {

	@Resource
	private ProgramLogsMapper programLogsMapper;

	@Override
	public int deleteByPrimaryKey(String id) {
		return programLogsMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteByIdBatch(List<String> ids) {
		int count = 0;
		for (String id : ids) {
			count += programLogsMapper.deleteByPrimaryKey(id);
		}
		return count;
	}

	@Override
	public int insert(ProgramLogs record) {
		return programLogsMapper.insert(record);
	}

	@Override
	public int insertSelective(ProgramLogs record) {
		return programLogsMapper.insertSelective(record);
	}

	@Override
	public ProgramLogs selectByPrimaryKey(String id) {
		return programLogsMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(ProgramLogs record) {
		return programLogsMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(ProgramLogs record) {
		return programLogsMapper.updateByPrimaryKey(record);
	}

	@Override
	public PagedResult<ProgramLogsVo> selectProgramLogsList(ProgramLogVo record) {
	    Integer	pageNo = record.getPageNo() == null ? 1 : record.getPageNo();
		Integer pageSize = record.getPageSize() == null ? 10 : record.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(programLogsMapper.selectProgramLogsList(record));
	}
	
	@Override
	public Integer getProgramLogsListCount(ProgramLogVo record) {
		return programLogsMapper.getProgramLogsListCount(record);
	}

	/**
	 * 清理三个月以前的日志
	 */
	@Override
	public int deleteLogsByThreeMonthAgo() {
		return programLogsMapper.deleteLogsByThreeMonthAgo();
	}
	
	/**
	 * 清理全部日志
	 * @return
	 */
	@Override
	public int deleteAllLogs(){
		return programLogsMapper.deleteAllLogs();
	}
}